<%@ page pageEncoding="UTF-8" %>
<!doctype html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.0/dist/css/bootstrap.min.css"
          integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
    <link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/5.6.3/css/all.css" rel="stylesheet">
    <link rel="stylesheet" href="https://unpkg.com/bootstrap-table@1.15.3/dist/bootstrap-table.min.css">
    <link href="https://cdn.bootcdn.net/ajax/libs/bootstrap-select/1.13.10/css/bootstrap-select.css" rel="stylesheet">
    <link href="https://cdn.bootcdn.net/ajax/libs/toastr.js/2.1.4/toastr.min.css" rel="stylesheet">
    <title>随便打TCS系统</title>
</head>

<body class="nav-md">
<div class="container-fluid" style="padding-left: 235px">
    <div>
        <div id="toolbar" class="btn-group">
            <div class="row">
                <div class="col-14" style="margin-left: 15px">
                    <form class="form-inline" id="formSelect">
                        <div class="form-group mb-2">
                            <input type="text" class="form-control" id="goldUserSelect" placeholder="获取积分用户">
                        </div>
                        <div class="form-group mb-2">
                        <select class="form-control" id="goldStatusSelect">
                            <option value="" selected:disabled style="diaplay:none">新增或减少</option>
                            <option value="0">减少</option>
                            <option value="1">新增</option>
                        </select>
                    </div>
                        <div class="form-group mb-2">
                            <select class="form-control" id="moneyTypeSelect">
                                <option value="" selected:disabled style="diaplay:none">是否冻结</option>
                                <option value="0">未冻结</option>
                                <option value="1">冻结</option>
                            </select>
                        </div>
                        <div class="form-group mb-2">
                            <button type="button" id="search" class="btn btn-success">查询</button>
                            <button type="reset" id="reset" class="btn btn-danger">重置</button>
                        </div>
                    </form>
                </div>
<%--                <div class="col-14" style="margin-left: 20px">--%>
<%--                    <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#addShow">--%>
<%--                        新增--%>
<%--                    </button>--%>
<%--                </div>--%>
            </div>
        </div>
        <table id="table"></table>
    </div>
    <!-- 新增 -->
    <div class="modal fade" id="addShow" tabindex="-1" role="dialog" aria-labelledby="addShowTitle">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title" id="addShowTitle">新增积分</h4>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                </div>
                <div class="modal-body">
                    <form id="formAdd">
                        <div class="form-row">
                            <div class="form-group " style="width: 100%">
                                <input type="text" class="form-control" id="addMobile" placeholder="请输入新增用户的手机号">
                            </div>
                        </div>
                        <div class="form-row">
                            <div class="form-group col-md-6">
                                <input type="number" class="form-control" id="addMoney" placeholder="请输入交易金额">
                            </div>
                        </div>
                        <div class="form-row">
                            <div class="form-group col-md-6">
                                <input type="text" class="form-control" id="addContext" placeholder="请输入交易内容">
                            </div>
                        </div>
                        <div class="form-row">
                            <div class="form-group col-md-6">
                                <select class="form-control" id="addStatus">
                                    <option value="" selected:disabled style="diaplay:none">请选择状态</option>
                                    <option value="0">减少</option>
                                    <option value="1">新增</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-row">
                            <div class="form-group col-md-6">
                                <select class="form-control" id="addType">
                                    <option value="" selected:disabled style="diaplay:none">是否冻结</option>
                                    <option value="0">正常</option>
                                    <option value="1">冻结</option>
                                </select>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button id="addPost" type="button" class="btn btn-primary">新增</button>
                </div>
            </div>
        </div>
    </div>

    <!-- 修改 -->
    <div class="modal fade" id="updateShow" tabindex="-1" role="dialog" aria-labelledby="updateShowTitle">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title" id="updateShowTitle">修改积分</h4>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                </div>
                <div class="modal-body">
                    <form id="formUpdate">
                        <input type="email" hidden class="form-control" id="idUpdate"/>
                        <div class="form-row">
                            <div class="form-group" style="width: 100%">
                                <label for="moneyGoldMobileUpdate">获利人手机号：</label>
                                <input type="text" class="form-control" id="moneyGoldMobileUpdate"
                                       placeholder="请输入受益人手机号">
                            </div>
                        </div>
                        <div class="form-row">
                            <div class="form-group col-md-6">
                                <label for="goldMoneyStatusUpdate">状态：</label>
                                <select class="form-control" id="goldMoneyStatusUpdate">
                                    <option value="0">减少</option>
                                    <option value="1">新增</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-row">
                            <div class="form-group col-md-6">
                                <label for="goldMoneyStyleUpdate">是否冻结：</label>
                                <select class="form-control" id="goldMoneyStyleUpdate">
                                    <option value="0">否</option>
                                    <option value="1">是</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-row">
                            <div class="form-group" style="width: 100%">
                                <label for="goldMoneyUpdate">修改金额：</label>
                                <input type="text" class="form-control" id="goldMoneyUpdate"
                                       placeholder="请输入金额">
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" id="updatePost">修改</button>
                </div>
            </div>
        </div>
    </div>

</div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"
        integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
        crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.0/dist/js/bootstrap.min.js"
        integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI"
        crossorigin="anonymous"></script>
<script src="https://unpkg.com/bootstrap-table@1.15.3/dist/bootstrap-table.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/bootstrap-table/1.15.3/locale/bootstrap-table-zh-CN.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/bootstrap-select/1.13.10/js/bootstrap-select.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/bootstrap-select/1.13.10/js/i18n/defaults-zh_CN.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/toastr.js/2.1.4/toastr.min.js"></script>
</html>
<script>
    $(function () {
        Date.prototype.Format = function (fmt) {
            var o = {
                "M+": this.getMonth() + 1,
                "d+": this.getDate(),
                "h+": this.getHours(),
                "m+": this.getMinutes(),
                "s+": this.getSeconds(),
                "q+": Math.floor((this.getMonth() + 3) / 3),
                "S": this.getMilliseconds()
            };
            if (/(y+)/.test(fmt))
                fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
            for (var k in o)
                if (new RegExp("(" + k + ")").test(fmt))
                    fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
            return fmt;
        };

        function isOutFormatter(value, row, index) {
            if (value === 0) {
                return '<p class="text-success">减少</p>';
            }
            if (value === 1) {
                return '<p class="text-danger">新增</p>';
            }
        }

        function isStatusFormatter(value, row, index) {
            if (value === 1) {
                return '<p class="text-success">增加</p>';
            }
            if (value === 0) {
                return '<p class="text-danger">减少</p>';
            }
        }

        function nameFormatter(value, row, index) {
            console.log(value)
            if (value!=null && value!="null") {
                return '<div class="badge badge-primary text-wrap" style="width: 6rem;">' + value + '</div>'
            }
            return "";
         }

        // function getUserTureInfo(id){
        //     var userinfo=null;
        //     $.ajax({
        //         url: "/SbdVoip/userinfo/getByUserId",
        //         type: "POST",
        //         data: {userId: id},
        //         dataType: "json",
        //         sy
        //         contentType: "application/x-www-form-urlencoded",
        //         success: function (result) {
        //             console.log("result:"+result)
        //           userinfo=result.data;
        //         }
        //     });
        //     return userinfo;
        // }
        function isActivityFormatter(value, row, index) {
            if (value === 1) {
                return '<p class="text-success">冻结</p>';
            }
            if (value === 0) {
                return '<p class="text-danger">正常</p>';
            }
        }

        function formatDate(value, row, index) {
            return new Date(parseInt(value)).Format("yyyy-MM-dd hh:mm:ss");
        }

        function actionFormatter(value, row, index) {
            return [
                '<button id="showUpdateId" type="button" class="btn btn-warning">修改</button>',
                '<button id="showDeleteId" type="button" class="btn btn-danger">删除</button>'
            ].join('');
        }

        window.operateEvents = {
            "click #showUpdateId": function (e, value, row, index) {
                $('#updateShow').modal('show');
                $('#idUpdate').val(row.id);
                $('#moneyGoldMobileUpdate').val(row.sub);
                $("#goldMoneyStatusUpdate option[text='jQuery']").attr("selected", true);
                $('#goldMoneyUpdate').val(row.money);
                $('#goldMoneyStyleUpdate').val(row.type);
            },
            "click #showDeleteId": function (e, value, row, index) {
                $.ajax({
                    url: "/SbdVoip/admin/ptIntegralWebDelete",
                    type: "POST",
                    data: {id: row.id},
                    dataType: "json",
                    contentType: "application/x-www-form-urlencoded",
                    success: function (result) {
                        if (result.code !== 2000) {
                            toastr.error(result.message);
                            return
                        }
                        var table = $('#table');
                        table.bootstrapTable('destroy');
                        table.bootstrapTable(bootstrapTable);
                        toastr.success(result.message);
                    }
                });
            }
        };
        var columns = [
            {checkbox: true, 'data-halign': 'center', width: 50},
            {field: 'id', title: '编号', align: 'left', width: 250},
            {field: 'sub', title: '用户', align: 'left', width: 50 , formatter: nameFormatter},
            {field: 'status', title: '状态', align: 'left', width: 100, formatter: isOutFormatter},
            {field: 'money', title: '交易金额', align: 'left', width: 100},
            {field: 'context', title: '交易内容', align: 'left', width: 100},
            {field: 'type', title: '状态', align: 'left', width: 100, formatter: isActivityFormatter},
            {field: 'createTime', title: '创建时间', align: 'left', width: 272, formatter: formatDate},
            {title: '操作', align: 'center', formatter: actionFormatter, events: operateEvents, width: 500}
        ];
        var bootstrapTable = {
            url: '/SbdVoip/admin/ptIntegralWebList',
            pagination: true,
            toolbar: '#toolbar',
            smartDisplay: false,
            showRefresh: true,
            height: $(window).height(),
            method: 'post',
            pageList: "[10, 15, 20]",
            search: false,
            contentType: 'application/x-www-form-urlencoded',
            dataType: 'json',
            sidePagination: 'server',
            pageNumber: 1,
            pageSize: 10,
            onlyInfoPagination: false,
            striped: true,
            columns: columns,
            onPostHeader: function () {
                $('#tableId').bootstrapTable('resetView');
            },
            queryParams: function (params) {
                return {
                    offset: (params.offset / params.limit) + 1,
                    limit: params.limit
                };
            },
            responseHandler: function (res) {
                if (res.code !== 2000) {
                    toastr.error(res.data);
                    return {
                        total: 0,
                        rows: []
                    }
                }
                return {
                    total: res.data.total,
                    rows: res.data.rows
                }
            }
        };

        $('#table').bootstrapTable(bootstrapTable);

        $("#updatePost").click(function () {
            var data = {
                updateId: $('#idUpdate').val(),
                updateStatus: $("#goldMoneyStatusUpdate").find("option:selected").val(),
                updateMoney: $('#goldMoneyUpdate').val(),
                updateMobile: $('#moneyGoldMobileUpdate').val(),
                updatetype:$('#goldMoneyStyleUpdate').find("option:selected").val()
            };
            $.ajax({
                url: "/SbdVoip/admin/ptIntegralWebUpdate",
                type: "POST",
                data: data,
                dataType: "json",
                contentType: "application/x-www-form-urlencoded",
                success: function (result) {
                    if (result.code !== 2000) {
                        toastr.error(result.message);
                        return
                    }
                    var updateShow = $('#updateShow');
                    updateShow.modal('hide');
                    var table = $('#table');
                    table.bootstrapTable('destroy');
                    table.bootstrapTable(bootstrapTable);
                    toastr.success(result.message);
                }
            });
        });
        $("#addPost").click(function () {
            var data = {
                addMobile: $('#addMobile').val(),
                addStatus: $("#addStatus").find("option:selected").val(),
                addMoney: $('#addMoney').val(),
                addContext: $('#addContext').val(),
                addType:$('#addType').val()
            };
            $.ajax({
                url: "/SbdVoip/admin/ptIntegralWebAdd",
                type: "POST",
                data: data,
                dataType: "json",
                contentType: "application/x-www-form-urlencoded",
                success: function (result) {
                    if (result.code !== 2000) {
                        toastr.error(result.message);
                        return
                    }
                    var addShow = $('#addShow');
                    addShow.modal('hide');
                    var table = $('#table')
                    table.bootstrapTable('destroy');
                    table.bootstrapTable(bootstrapTable);
                    toastr.success(result.message);
                }
            });
        });
        $('#search').click(function () {
            var goldUser = $('#goldUserSelect').val();
            var goldStatus = $("#goldStatusSelect").find("option:selected").val();
            var type=$("#moneyTypeSelect").find("option:selected").val();
            bootstrapTable.queryParams = function (params) {
                return {
                    offset: (params.offset / params.limit) + 1,
                    limit: params.limit,
                    mobile: goldUser,
                    status: goldStatus,
                    type:type
                };
            };
            var table = $('#table');
            table.bootstrapTable('destroy');
            table.bootstrapTable(bootstrapTable);
        });
    });
</script>
